//
// Created by Administrator on 2021/9/15.
//
#include<stdio.h>
#include<stdlib.h>
#define CAND 5
#define PW_CNT 5
void xuanxiu(){
    int cand_score[CAND][PW_CNT];
    double cand_avg_score[CAND];
    double tmp_cand_avg_score[CAND];
    for(int cand = 0;cand<CAND;cand++){
        for(int pw = 0;pw<PW_CNT;pw++){
            cand_score[cand][pw] = rand()%10;
            printf("%d ",cand_score[cand][pw]);
        }
        printf("\n");
    }

    //计算选手平均分
    for(int cand=0;cand<CAND;cand++){
        int cur_min = 10;
        int cur_max = 0;
        int tot_scr = 0;
        for(int pw=0;pw<PW_CNT;pw++){
            int cur_scr = cand_score[cand][pw];
            tot_scr += cur_scr;
            if(cur_scr<cur_min) cur_min = cur_scr;
            if(cur_scr>cur_max) cur_max = cur_scr;
        }
        cand_avg_score[cand] = (tot_scr-cur_max-cur_min)/3.0;
        tmp_cand_avg_score[cand] = cand_avg_score[cand];
    }

    //对选手进行排名并输出结果
    for(int i=0;i<CAND;i++){
        int max_pos = -1;
        double max_scr = 0.0;
        for(int j=0;j<CAND;j++){
            if(tmp_cand_avg_score[j] > max_scr){
                max_scr = tmp_cand_avg_score[j];
                max_pos = j;
            }
        }
        printf("rank %d: player %d, score %f\n",i+1,max_pos,tmp_cand_avg_score[max_pos]);
        tmp_cand_avg_score[max_pos] = -1.0;
    }

    for(int i=0;i<CAND;i++){
        tmp_cand_avg_score[i] = cand_avg_score[i];
    }

    //对评委打分精确度进行计算，计算规则为100/总误差，计算结果越大打分越准确
    double pw_score[PW_CNT];
    for(int pw=0;pw<PW_CNT;pw++){
        for(int cand=0;cand<CAND;cand++){
            double delta = cand_score[cand][pw]-tmp_cand_avg_score[cand];
            if(delta < 0) delta*=-1;
            pw_score[pw] += delta;
        }
        pw_score[pw] = 100/pw_score[pw];
        printf("reviewer %d: precision %f\n",pw,pw_score[pw]);
    }
}
